<template>
  <view class="container page-with-cunba-nav">
    <!-- 顶部导航栏 -->
    <view class="custom-nav-bar" :style="{ paddingTop: statusBarHeight + 'px' }">
      <view class="nav-content">
        <view class="nav-left" @click="goBack">
          <text class="back-icon">‹</text>
        </view>
        <view class="nav-title">我的</view>
        <view class="nav-right"></view>
      </view>
    </view>
    
    <!-- 顶部用户信息区域 -->
    <view class="user-header">
      <view class="user-info">
        <view class="avatar-section">
          <image class="user-avatar" :src="userInfo.avatar" mode="aspectFill"></image>
        </view>
        <view class="user-details">
          <view class="user-phone">{{ userInfo.phone }}</view>
          <view class="user-description">{{ userInfo.description }}</view>
        </view>
      </view>
      
      <!-- 统计数据 -->
      <view class="stats-section">
        <view class="stat-item" @click="viewStats('wonderful')">
          <text class="stat-number">{{ stats.wonderful }}</text>
          <text class="stat-label">精彩次数</text>
        </view>
        <view class="stat-item" @click="viewStats('views')">
          <text class="stat-number">{{ stats.views }}</text>
          <text class="stat-label">观看次数</text>
        </view>
        <view class="stat-item" @click="viewStats('follows')">
          <text class="stat-number">{{ stats.follows }}</text>
          <text class="stat-label">关注球队</text>
        </view>
      </view>
    </view>

    <!-- 酒店推广横幅 -->
    <view class="promotion-banner" @click="viewPromotion">
      <view class="banner-content">
        <view class="banner-text">
          <text class="banner-title">看村BA 住六盘水市民宿</text>
          <text class="banner-subtitle">现场入住</text>
          <text class="banner-price">全15间</text>
        </view>
        <image class="banner-image" src="https://cdn.xryai.cn/picGo/20250907201956493.png" mode="aspectFit"></image>
      </view>
    </view>

    <!-- 更多功能 -->
    <view class="more-functions">
      <text class="section-title">更多功能</text>
    </view>

    <!-- 功能菜单 -->
    <view class="function-menu">
      <view class="menu-item" @click="navigateToPage('booking')">
        <view class="menu-icon">
          <image src="/static/images/tyc.png" mode="aspectFit"></image>
        </view>
        <text class="menu-text">我的预约</text>
        <text class="arrow-text">></text>
      </view>
      
      <view class="menu-item" @click="navigateToPage('attention')">
        <view class="menu-icon">
          <image src="/static/images/mine.png" mode="aspectFit"></image>
        </view>
        <text class="menu-text">我的关注</text>
        <text class="arrow-text">></text>
      </view>
    </view>

    <!-- 底部提示文字 -->
    <view class="bottom-tip">
      <text class="tip-text">感谢您使用村BA赛事平台</text>
    </view>

    <!-- 自定义导航栏 -->
    <cunba-nav-bar :activeIndex="3" :badges="navBadges" @nav-change="onNavChange"></cunba-nav-bar>
  </view>
</template>

<script>
import CunbaNavBar from '@/components/cunba-nav-bar/index.vue'

export default {
  components: {
    CunbaNavBar
  },
  data() {
    return {
      // 状态栏高度
      statusBarHeight: 0,
      // 导航栏角标配置
      navBadges: {
        home: 0,
        schedule: 0,
        team: 0,
        mine: 0
      },
      // 用户信息
      userInfo: {
        avatar: '/static/images/mine.png', // 使用默认头像图标
        phone: '152****5201',
        description: '152****5201 HBA选球亲友好'
      },
      // 统计数据
      stats: {
        wonderful: 1,
        views: 0,
        follows: 0
      }
    }
  },
  onLoad() {
    console.log('我的页面加载完成')
    this.initUserData()
    this.setStatusBarHeight()
  },
  methods: {
    // 初始化用户数据
    initUserData() {
      // 这里可以从本地存储或服务器获取用户数据
      console.log('初始化用户数据')
      
      // 模拟从服务器获取用户数据
      setTimeout(() => {
        this.userInfo = {
          ...this.userInfo,
          description: '村BA资深球迷，关注赛事动态'
        }
      }, 1000)
    },
    
    // 查看统计详情
    viewStats(type) {
      console.log('查看统计详情:', type)
      switch(type) {
        case 'wonderful':
          uni.showToast({
            title: '精彩次数详情',
            icon: 'none'
          })
          break
        case 'views':
          uni.showToast({
            title: '观看次数详情',
            icon: 'none'
          })
          break
        case 'follows':
          uni.showToast({
            title: '关注球队详情',
            icon: 'none'
          })
          break
      }
    },
    
    // 查看推广详情
    viewPromotion() {
      console.log('查看酒店推广')
      uni.showModal({
        title: '酒店推广',
        content: '看村BA 住国宾馆\n现场入住享受优惠价格',
        confirmText: '了解详情',
        success: (res) => {
          if (res.confirm) {
            // 跳转到酒店详情页面或外部链接
            // uni.navigateTo({
            //   url: '/pages/hotel/detail/index'
            // })
          }
        }
      })
    },
    
    // 导航到指定页面
    navigateToPage(type) {
      console.log('导航到页面:', type)
      switch(type) {
        case 'booking':
          uni.showToast({
            title: '我的预约功能开发中',
            icon: 'none'
          })
          // uni.navigateTo({
          //   url: '/pages/user/booking/index'
          // })
          break
        case 'attention':
          uni.showToast({
            title: '我的关注功能开发中',
            icon: 'none'
          })
          // uni.navigateTo({
          //   url: '/pages/user/attention/index'
          // })
          break
      }
    },
    
    // 自定义导航栏切换事件
    onNavChange(navData) {
      console.log('导航栏切换:', navData)
    },
    
    // 返回上一页
    goBack() {
      uni.navigateBack({
        delta: 1
      })
    },
    
    // 设置状态栏高度
    setStatusBarHeight() {
      // 获取系统信息
      const systemInfo = uni.getSystemInfoSync()
      this.statusBarHeight = systemInfo.statusBarHeight || 0
      
      // 设置CSS变量
      // #ifdef APP-PLUS
      document.documentElement.style.setProperty('--status-bar-height', this.statusBarHeight + 'px')
      // #endif
      
      console.log('状态栏高度:', this.statusBarHeight)
    },
    
    // 下拉刷新
    onPullDownRefresh() {
      setTimeout(() => {
        this.initUserData()
        uni.stopPullDownRefresh()
      }, 1000)
    }
  }
}
</script>

<style lang="scss" scoped>
.container {
  background: linear-gradient(180deg, #4A6CF7 0%, #667EEA 100%);
  min-height: 100vh;
  position: relative;
}

/* 自定义导航栏 */
.custom-nav-bar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  z-index: 999;
  
  .nav-content {
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 15px;
    
    .nav-left {
      width: 44px;
      height: 44px;
      display: flex;
      align-items: center;
      justify-content: center;
      cursor: pointer;
      
      .back-icon {
        font-size: 24px;
        color: #fff;
        font-weight: bold;
      }
      
      &:active {
        opacity: 0.7;
      }
    }
    
    .nav-title {
      flex: 1;
      text-align: center;
      font-size: 18px;
      font-weight: bold;
      color: #fff;
    }
    
    .nav-right {
      width: 44px;
      height: 44px;
    }
  }
}

/* 用户头部信息 */
.user-header {
  /* #ifdef APP-PLUS */
  padding: calc(var(--status-bar-height) + 64px) 20px 30px;
  /* #endif */
  /* #ifdef H5 */
  padding: 104px 20px 30px;
  /* #endif */
  /* #ifdef MP */
  padding: calc(var(--status-bar-height, 44px) + 64px) 20px 30px;
  /* #endif */
  color: #fff;
}

.user-info {
  display: flex;
  align-items: center;
  margin-bottom: 30px;
  
  .avatar-section {
    margin-right: 15px;
    
    .user-avatar {
      width: 60px;
      height: 60px;
      border-radius: 30px;
      border: 3px solid rgba(255, 255, 255, 0.3);
    }
  }
  
  .user-details {
    flex: 1;
    
    .user-phone {
      font-size: 20px;
      font-weight: bold;
      color: #fff;
      margin-bottom: 5px;
    }
    
    .user-description {
      font-size: 14px;
      color: rgba(255, 255, 255, 0.8);
    }
  }
}

.stats-section {
  display: flex;
  justify-content: space-around;
  background: rgba(255, 255, 255, 0.15);
  border-radius: 15px;
  padding: 20px 0;
  backdrop-filter: blur(10px);
  
  .stat-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    cursor: pointer;
    transition: transform 0.2s;
    
    &:active {
      transform: scale(0.95);
    }
    
    .stat-number {
      font-size: 24px;
      font-weight: bold;
      color: #fff;
      margin-bottom: 5px;
    }
    
    .stat-label {
      font-size: 12px;
      color: rgba(255, 255, 255, 0.8);
    }
  }
}

/* 推广横幅 */
.promotion-banner {
  margin: 20px;
  background: linear-gradient(135deg, #FF6B6B 0%, #FF8E8E 100%);
  border-radius: 15px;
  overflow: hidden;
  cursor: pointer;
  transition: transform 0.2s;
  
  &:active {
    transform: scale(0.98);
  }
  
  .banner-content {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 15px 20px;
    
    .banner-text {
      flex: 1;
      
      .banner-title {
        display: block;
        font-size: 16px;
        font-weight: bold;
        color: #fff;
        margin-bottom: 5px;
      }
      
      .banner-subtitle {
        display: block;
        font-size: 12px;
        color: rgba(255, 255, 255, 0.9);
        margin-bottom: 3px;
      }
      
      .banner-price {
        display: block;
        font-size: 14px;
        font-weight: bold;
        color: #fff;
      }
    }
    
    .banner-image {
      width: 80px;
      height: 60px;
      border-radius: 8px;
    }
  }
}

/* 更多功能标题 */
.more-functions {
  padding: 0 20px;
  margin-top: 10px;
  margin-bottom: 15px;
  
  .section-title {
    font-size: 16px;
    color: rgba(255, 255, 255, 0.9);
    font-weight: 500;
  }
}

/* 功能菜单 */
.function-menu {
  margin: 0 20px;
  background: rgba(255, 255, 255, 0.15);
  border-radius: 15px;
  backdrop-filter: blur(10px);
  overflow: hidden;
  
  .menu-item {
    display: flex;
    align-items: center;
    padding: 18px 20px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    cursor: pointer;
    transition: background-color 0.2s;
    
    &:last-child {
      border-bottom: none;
    }
    
    &:active {
      background-color: rgba(255, 255, 255, 0.1);
    }
    
    .menu-icon {
      width: 24px;
      height: 24px;
      margin-right: 15px;
      
      image {
        width: 100%;
        height: 100%;
        filter: brightness(0) invert(1);
      }
    }
    
    .menu-text {
      flex: 1;
      font-size: 16px;
      color: #fff;
    }
    
    .arrow-text {
      font-size: 16px;
      color: rgba(255, 255, 255, 0.6);
      font-weight: bold;
    }
  }
}

/* 底部提示文字 */
.bottom-tip {
  position: absolute;
  bottom: 110px;
  left: 0;
  right: 0;
  text-align: center;
  
  .tip-text {
    font-size: 12px;
    color: rgba(255, 255, 255, 0.6);
  }
}

/* 页面容器样式 */
.page-with-cunba-nav {
  padding-bottom: calc(80px + env(safe-area-inset-bottom));
}

/* 页面进入动画 */
.container {
  animation: fadeInUp 0.6s ease-out;
}

@keyframes fadeInUp {
  0% {
    opacity: 0;
    transform: translateY(30px);
  }
  100% {
    opacity: 1;
    transform: translateY(0);
  }
}

/* 统计项悬停效果 */
.stat-item:hover {
  transform: scale(1.05);
}

/* 功能菜单项悬停效果 */
.menu-item:hover {
  background-color: rgba(255, 255, 255, 0.1);
}
</style>
